package tasker;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.mt4j.MTApplication;
import org.mt4j.components.MTComponent;
import org.mt4j.components.TransformSpace;
import org.mt4j.components.visibleComponents.font.FontManager;
import org.mt4j.components.visibleComponents.font.IFont;
import org.mt4j.components.visibleComponents.shapes.AbstractShape;
import org.mt4j.components.visibleComponents.shapes.MTRectangle.PositionAnchor;
import org.mt4j.components.visibleComponents.widgets.MTList;
import org.mt4j.components.visibleComponents.widgets.MTListCell;
import org.mt4j.components.visibleComponents.widgets.MTTextArea;
import org.mt4j.components.visibleComponents.widgets.MTTextArea.ExpandDirection;
import org.mt4j.components.visibleComponents.widgets.buttons.MTImageButton;
import org.mt4j.components.visibleComponents.widgets.buttons.MTSvgButton;
import org.mt4j.components.visibleComponents.widgets.keyboard.MTKeyboard;
import org.mt4j.input.gestureAction.DefaultDragAction;
import org.mt4j.input.gestureAction.InertiaDragAction;
import org.mt4j.input.inputProcessors.IGestureEventListener;
import org.mt4j.input.inputProcessors.MTGestureEvent;
import org.mt4j.input.inputProcessors.componentProcessors.dragProcessor.DragProcessor;
import org.mt4j.input.inputProcessors.componentProcessors.tapProcessor.TapEvent;
import org.mt4j.input.inputProcessors.componentProcessors.tapProcessor.TapProcessor;
import org.mt4j.input.inputProcessors.globalProcessors.CursorTracer;
import org.mt4j.sceneManagement.AbstractScene;
import org.mt4j.sceneManagement.IPreDrawAction;
import org.mt4j.sceneManagement.Iscene;
import org.mt4j.util.MT4jSettings;
import org.mt4j.util.MTColor;
import org.mt4j.util.math.Vector3D;


import processing.core.PImage;

/*
 * Componentes da tela: 
 * 		- 3 listas de componentes do tipo TextArea - "TO BE DONE"/"DOING"/"DONE"
 * 		- bot�o para chamar o MTKeyboard para que possamos digitar a tarefa. 
 * 			(N�o sei se vamos presisar criar um bot�o para cada tipo de lista)
 * 		- Ao preencher o texto com o nome da tarefa, precisaremos criar um componente do tipo MTTextArea na lista crrespondente 
 */


public class MTGesturesScene2 extends AbstractScene {
	private MTApplication app;
	
	//Cria uma lista de MTTextArea 
	private List<MTTasker> toBeDoneList;
	private List<MTTasker> doingList;
	private List<MTTasker> doneList;	
	
	MTPanel painelToBeDone;
	MTPanel painelDoing;
	MTPanel painelDone;
	
	//private ArrayList<MTTextArea> doingList;
	private Iscene scene2;
	
	private String imagePath =  "tasker" + MTApplication.separator + "data" + MTApplication.separator;

	public MTGesturesScene2(MTApplication mtApplication, String name) {
		super(mtApplication, name);
		this.app = mtApplication;
		this.setClearColor(new MTColor(126, 130, 168, 255));
		this.registerGlobalInputProcessor(new CursorTracer(app, this));

		final float verticalPad = 50;
		final float horizontalPad = 10;
		
		
		MTColor white = new MTColor(255,255,255);
		final MTColor textAreaColor = new MTColor(50,50,50,255);
		
		final IFont font = FontManager.getInstance().createFont(app, "arial.ttf", 35, white, white);
		
		//Lista de tarefas "To be done", "Doing", "Done"
		this.toBeDoneList = new ArrayList<MTTasker>(); 
		this.doingList = new ArrayList<MTTasker>();
		this.doneList = new ArrayList<MTTasker>();	


		
		//Add canvas background gestures
		//Zoom gesture
		/*MTTextArea backgroundZoom = new MTTextArea(mtApplication, font);
		backgroundZoom.setFillColor(new MTColor(150,150,150));
		backgroundZoom.setNoFill(true);
		backgroundZoom.setNoStroke(true);
		backgroundZoom.setText("Zoom anywhere on the background!");
		backgroundZoom.setPickable(false);
		this.getCanvas().addChild(backgroundZoom);
		backgroundZoom.setPositionGlobal(new Vector3D(app.width/2f, app.height/2f,0));
		getCanvas().registerInputProcessor(new ZoomProcessor(app));
		getCanvas().addGestureListener(ZoomProcessor.class, new DefaultZoomAction());*/
		
		//2 finger pan gesture
		/*MTTextArea backgroundPan = new MTTextArea(mtApplication, font);
		backgroundPan.setFillColor(new MTColor(150,150,150));
		backgroundPan.setNoFill(true);
		backgroundPan.setNoStroke(true);
		backgroundPan.setText("Pan anywhere on the background!");
		backgroundPan.setPickable(false);
		this.getCanvas().addChild(backgroundPan);
		backgroundPan.setPositionGlobal(new Vector3D(app.width/2f, app.height/2f + 1*verticalPad,0));
		getCanvas().registerInputProcessor(new PanProcessorTwoFingers(app));
		getCanvas().addGestureListener(PanProcessorTwoFingers.class, new DefaultPanAction());*/
				
		//para tentar fazer o scroll
		/*MTList aList = new MTList(100, 50, 200, 400, mtApplication);
		MTListCell listCell = new MTListCell(200, 600, mtApplication);
		MTTextArea texta = new MTTextArea(0,0, 200,600, mtApplication);
		texta.setText("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,\n no sea takimata sanctus est Lorem ipsum dolor sit amet. \nDuis autem ve Lorem ipsum dolor sit amet. adi�s!");
		listCell.addChild(texta);
		aList.addListElement(listCell);
		getCanvas().addChild(aList);*/		
		
		//Load from file system - repetido - vrf depois
		PImage imgPanel1 = app.loadImage(imagePath + "ToBeDone.png");		
		
		//Cria os MTPanels "To Be Done", "Doing", "Done"
		this.painelToBeDone = new MTPanel(imgPanel1, app);
		//painelToBeDone.setSizeXYGlobal(0, 0);
		//painelToBeDone.setPositionGlobal(new Vector3D(get  50,50));//new Vector3D(getCenterPointGlobal().x+this.getWidthXYGlobal() , getCenterPointGlobal().y));
		painelToBeDone.setFillColor(MTColor.WHITE);//new MTColor(0,255,0,180));
		painelToBeDone.setAnchor(PositionAnchor.UPPER_LEFT);
		this.getCanvas().addChild(painelToBeDone);
		
		this.painelDoing = new MTPanel(imgPanel1, app);
		//painelDoing.setSizeXYGlobal(0, 0);
		painelDoing.setPositionRelativeToParent(new Vector3D(painelToBeDone.getWidthXY(TransformSpace.RELATIVE_TO_PARENT)+200, 1-painelToBeDone.getHeightXY(TransformSpace.RELATIVE_TO_PARENT)+760));
		painelDoing.setFillColor(MTColor.WHITE);//new MTColor(0,255,0,180));
		this.getCanvas().addChild(painelDoing);
		
		this.painelDone = new MTPanel(imgPanel1, app);
		//painelDone.setSizeXYGlobal(0, 0);
		painelDone.setPositionRelativeToParent(new Vector3D(painelDoing.getWidthXY(TransformSpace.RELATIVE_TO_PARENT)+570, 1-painelDoing.getHeightXY(TransformSpace.RELATIVE_TO_PARENT)+760));
		painelDone.setFillColor(MTColor.WHITE);//new MTColor(0,255,0,180));
		this.getCanvas().addChild(painelDone);
		
		//Add component multi-touch gestures
		MTTextArea textToBeDone = new MTTextArea(mtApplication, font);
		painelToBeDone.addChild(textToBeDone);
		textToBeDone.setAnchor(PositionAnchor.UPPER_LEFT);
		textToBeDone.setPositionRelativeToParent(painelToBeDone.getPosition(TransformSpace.LOCAL));
   		textToBeDone.setFillColor(textAreaColor);
		textToBeDone.setStrokeColor(textAreaColor);
		textToBeDone.setText("TO BE DONE");
		//this.clearAllGestures(dragOnly);
		//dragOnly.registerInputProcessor(new DragProcessor(app));
		//dragOnly.addGestureListener(DragProcessor.class, new DefaultDragAction());
		//dragOnly.addGestureListener(DragProcessor.class, new InertiaDragAction()); //Add inertia to dragging

		MTTextArea textDoing = new MTTextArea(mtApplication, font);
		painelDoing.addChild(textDoing);
		//textDoing.setPositionRelativeToParent(painelDoing.getPosition(TransformSpace.LOCAL));
		textDoing.setFillColor(textAreaColor);
		textDoing.setStrokeColor(textAreaColor);
		textDoing.setText("DOING");
	
		MTTextArea textDone = new MTTextArea(mtApplication, font);
		painelDone.addChild(textDone);
		//textDone.setPositionRelativeToParent(painelDone.getPosition(TransformSpace.LOCAL));
   		textDone.setFillColor(textAreaColor);
		textDone.setStrokeColor(textAreaColor);
		textDone.setText("DONE");
		
		//Load from file system - repetido - vrf depois
		PImage keyboardImg = app.loadImage(imagePath + "keyb128.png");
		
		final MTImageButton keyboardButton1 = new MTImageButton(keyboardImg, app);
		keyboardButton1.setFillColor(new MTColor(255,255,255,200));
		keyboardButton1.setName("KeyboardButton1");
		keyboardButton1.setNoStroke(true);
		keyboardButton1.setSizeLocal(50, 50);
		//keyboardButton.translateGlobal(new Vector3D(100,100,0));
		keyboardButton1.translateGlobal(new Vector3D(0+textToBeDone.getWidthXY(TransformSpace.GLOBAL),0,0));
		textToBeDone.addChild(keyboardButton1);			



		keyboardButton1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae) {
				switch (ae.getID()) {
				case TapEvent.BUTTON_CLICKED:
					//Flickr Keyboard
			        MTKeyboard keyb1 = new MTKeyboard(app);
			        keyb1.setFillColor(new MTColor(30, 30, 30, 210));
			        keyb1.setStrokeColor(new MTColor(0,0,0,255));
			        keyb1.setSizeXYGlobal(300, 150);
			        
			        final MTTextArea t1 = new MTTextArea(app, FontManager.getInstance().createFont(app, "arial.ttf", 50, 
			        		new MTColor(0,0,0,255), //Fill color 
							new MTColor(0,0,0,255))); //Stroke color
			        t1.setExpandDirection(ExpandDirection.UP);
					t1.setStrokeColor(new MTColor(0,0 , 0, 255));
					t1.setFillColor(new MTColor(205,200,177, 255));
					t1.unregisterAllInputProcessors();
					t1.setEnableCaret(true);
					t1.snapToKeyboard(keyb1);
					keyb1.addTextInputListener(t1);
			        
			        //Flickr Button for the keyboard
			        MTSvgButton flickrButton1 = new MTSvgButton( imagePath + "Flickr_Logo.svg", app);
			        flickrButton1.scale(0.4f, 0.4f, 1, new Vector3D(0,0,0), TransformSpace.LOCAL);
			        flickrButton1.translate(new Vector3D(0, 15,0));
			        flickrButton1.setBoundsPickingBehaviour(AbstractShape.BOUNDS_ONLY_CHECK);

			        /*flickrButton.addGestureListener(TapProcessor.class, new IGestureEventListener() {
						@Override
						public boolean processGestureEvent(MTGestureEvent ge) {
							switch (ge.getId()) {
							case 0:
								emailToSend = t.getText();
								notifySendEmail();
								break;
							default:
								break;
							}
							return false;
						}
					});*/
			      //Add actionlistener to flickr button
			        flickrButton1.addActionListener(new ActionListener() {
						
			        	int p1 = 1;
			        	public void actionPerformed(ActionEvent arg0) {
							
							if (arg0.getSource() instanceof MTComponent){
								//MTBaseComponent clickedComp = (MTBaseComponent)arg0.getSource();
								switch (arg0.getID()) {
								case TapEvent.BUTTON_CLICKED:
		        
							        System.out.println("Flickr search for: \"" + t1.getText() + "\"");
					        
							        //Cria um componente MTTextArea
							        MTTasker tarefa= new MTTasker(app, font);
							        painelToBeDone.addChild(tarefa);
							        tarefa.setTipo("TO BE DONE");
							        tarefa.setFillColor(textAreaColor);
							        tarefa.setAnchor(PositionAnchor.UPPER_LEFT);
							        tarefa.setPositionRelativeToParent(painelToBeDone.getPosition(TransformSpace.LOCAL));
							        tarefa.setStrokeColor(textAreaColor);
							        tarefa.setText(t1.getText());
									clearAllGestures(tarefa);
									tarefa.registerInputProcessor(new DragProcessor(app));
									tarefa.addGestureListener(DragProcessor.class, new DefaultDragAction());
									tarefa.addGestureListener(DragProcessor.class, new InertiaDragAction()); //Add inertia to dragging
									tarefa.setPositionGlobal(new Vector3D(horizontalPad, p1*verticalPad+20,0));
									//tarefa.setPositionRelativeToParent(painelToBeDone.getPosition(TransformSpace.LOCAL));
									p1++;
									
							        toBeDoneList.add(tarefa); 
							    							        
									/*MTTextArea rotateOnly = new MTTextArea(mtApplication, font);
									rotateOnly.setFillColor(textAreaColor);
									rotateOnly.setStrokeColor(textAreaColor);
									rotateOnly.setText("Rotate me!");
									this.clearAllGestures(rotateOnly);
									rotateOnly.registerInputProcessor(new RotateProcessor(app));
									rotateOnly.addGestureListener(RotateProcessor.class, new DefaultRotateAction());
									this.getCanvas().addChild(rotateOnly);
									rotateOnly.setAnchor(PositionAnchor.UPPER_LEFT);
									rotateOnly.setPositionGlobal(new Vector3D(0, verticalPad,0));*/
							        
							        t1.clear();
									break;
								default:
									break;
								}
							}
						}
					});
					keyb1.addChild(flickrButton1);
					
					getCanvas().addChild(keyb1);
					keyb1.setPositionGlobal(new Vector3D(app.width/2f, app.height/2f,0));
					
					
					System.out.println("Flickr search for: \"" + t1.getText() + "\"");	
					break;
				//case TapEvent.:
					
				default:
					break;
				}
			}
		});

		final MTImageButton keyboardButton2 = new MTImageButton(keyboardImg, app);
		keyboardButton2.setFillColor(new MTColor(255,255,255,200));
		keyboardButton2.setName("KeyboardButton2");
		keyboardButton2.setNoStroke(true);
		keyboardButton2.setSizeLocal(50, 50);
		//keyboardButton.translateGlobal(new Vector3D(100,100,0));
		keyboardButton2.translateGlobal(new Vector3D(0+textDoing.getWidthXY(TransformSpace.GLOBAL),0,0));
		textDoing.addChild(keyboardButton2);			

		keyboardButton2.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae) {
				switch (ae.getID()) {
				case TapEvent.BUTTON_CLICKED:
					//Flickr Keyboard
			        MTKeyboard keyb2 = new MTKeyboard(app);
			        keyb2.setFillColor(new MTColor(30, 30, 30, 210));
			        keyb2.setStrokeColor(new MTColor(0,0,0,255));
			        keyb2.setSizeXYGlobal(300, 150);
			        
			        final MTTextArea t1 = new MTTextArea(app, FontManager.getInstance().createFont(app, "arial.ttf", 50, 
			        		new MTColor(0,0,0,255), //Fill color 
							new MTColor(0,0,0,255))); //Stroke color
			        t1.setExpandDirection(ExpandDirection.UP);
					t1.setStrokeColor(new MTColor(0,0 , 0, 255));
					t1.setFillColor(new MTColor(205,200,177, 255));
					t1.unregisterAllInputProcessors();
					t1.setEnableCaret(true);
					t1.snapToKeyboard(keyb2);
					keyb2.addTextInputListener(t1);
			        
			        //Flickr Button for the keyboard
			        MTSvgButton flickrButton1 = new MTSvgButton( imagePath + "Flickr_Logo.svg", app);
			        flickrButton1.scale(0.4f, 0.4f, 1, new Vector3D(0,0,0), TransformSpace.LOCAL);
			        flickrButton1.translate(new Vector3D(0, 15,0));
			        flickrButton1.setBoundsPickingBehaviour(AbstractShape.BOUNDS_ONLY_CHECK);

			      //Add actionlistener to flickr button
			        flickrButton1.addActionListener(new ActionListener() {
						
			        	int p1 = 1;
			        	public void actionPerformed(ActionEvent arg0) {
							
							if (arg0.getSource() instanceof MTComponent){
								//MTBaseComponent clickedComp = (MTBaseComponent)arg0.getSource();
								switch (arg0.getID()) {
								case TapEvent.BUTTON_CLICKED:
																        
							        System.out.println("Flickr search for: \"" + t1.getText() + "\"");
					        
							        //Cria um componente MTTextArea
							        MTTasker tarefa= new MTTasker(app, font);
							        painelDoing.addChild(tarefa);
							        tarefa.setTipo("DOING");
							        tarefa.setFillColor(textAreaColor);
							        tarefa.setAnchor(PositionAnchor.UPPER_LEFT);
							        tarefa.setPositionRelativeToParent(painelDoing.getPosition(TransformSpace.LOCAL));
							        tarefa.setStrokeColor(textAreaColor);
							        tarefa.setText(t1.getText());
									clearAllGestures(tarefa);
									tarefa.registerInputProcessor(new DragProcessor(app));
									tarefa.addGestureListener(DragProcessor.class, new DefaultDragAction());
									tarefa.addGestureListener(DragProcessor.class, new InertiaDragAction()); //Add inertia to dragging
									//tarefa.setPositionGlobal(new Vector3D(painelDoing.getWidthXY(TransformSpace.RELATIVE_TO_PARENT)+50, p1*verticalPad+20,0));
									tarefa.setPositionGlobal(new Vector3D(painelDoing.getWidthXY(TransformSpace.RELATIVE_TO_PARENT)+40, p1*verticalPad+20,0));
									p1++;
									
							        doingList.add(tarefa); 
							        	
							        tarefa.addGestureListener(TapProcessor.class, new IGestureEventListener() {
										public boolean processGestureEvent(MTGestureEvent ge) {
											TapEvent te = (TapEvent)ge;
											switch (te.getTapID()) { 
											case TapEvent.BUTTON_CLICKED:
												//mostra a tarefa
											
												break;
											}
											return false;
										}
									});
							        
							        t1.clear();
									break;
								default:
									break;
								}
							}
						}
					});
					keyb2.addChild(flickrButton1);
					
					getCanvas().addChild(keyb2);
					keyb2.setPositionGlobal(new Vector3D(app.width/2f, app.height/2f,0));
					
					
					System.out.println("Flickr search for: \"" + t1.getText() + "\"");	
					break;
				//case TapEvent.:
					
				default:
					break;
				}
			}
		});
		
		final MTImageButton keyboardButton3 = new MTImageButton(keyboardImg, app);
		keyboardButton3.setFillColor(new MTColor(255,255,255,200));
		keyboardButton3.setName("KeyboardButton3");
		keyboardButton3.setNoStroke(true);
		keyboardButton3.setSizeLocal(50, 50);
		//keyboardButton.translateGlobal(new Vector3D(100,100,0));
		keyboardButton3.translateGlobal(new Vector3D(0+textDone.getWidthXY(TransformSpace.GLOBAL),0,0));
		textDone.addChild(keyboardButton3);			

		keyboardButton3.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae) {
				switch (ae.getID()) {
				case TapEvent.BUTTON_CLICKED:
					//Flickr Keyboard
			        MTKeyboard keyb3 = new MTKeyboard(app);
			        keyb3.setFillColor(new MTColor(30, 30, 30, 210));
			        keyb3.setStrokeColor(new MTColor(0,0,0,255));
			        keyb3.setSizeXYGlobal(300, 150);
			        
			        final MTTextArea t1 = new MTTextArea(app, FontManager.getInstance().createFont(app, "arial.ttf", 50, 
			        		new MTColor(0,0,0,255), //Fill color 
							new MTColor(0,0,0,255))); //Stroke color
			        t1.setExpandDirection(ExpandDirection.UP);
					t1.setStrokeColor(new MTColor(0,0 , 0, 255));
					t1.setFillColor(new MTColor(205,200,177, 255));
					t1.unregisterAllInputProcessors();
					t1.setEnableCaret(true);
					t1.snapToKeyboard(keyb3);
					keyb3.addTextInputListener(t1);
			        
			        //Flickr Button for the keyboard					
			        MTSvgButton flickrButton1 = new MTSvgButton( imagePath + "Flickr_Logo.svg", app);
			        flickrButton1.scale(0.4f, 0.4f, 1, new Vector3D(0,0,0), TransformSpace.LOCAL);
			        flickrButton1.translate(new Vector3D(0, 15,0));
			        flickrButton1.setBoundsPickingBehaviour(AbstractShape.BOUNDS_ONLY_CHECK);

			      //Add actionlistener to flickr button
			        flickrButton1.addActionListener(new ActionListener() {
						
			        	int p1 = 1;
			        	public void actionPerformed(ActionEvent arg0) {
							
							if (arg0.getSource() instanceof MTComponent){
								//MTBaseComponent clickedComp = (MTBaseComponent)arg0.getSource();
								switch (arg0.getID()) {
								case TapEvent.BUTTON_CLICKED:
														        
							        System.out.println("Flickr search for: \"" + t1.getText() + "\"");
					        
							        //Cria um componente MTTextArea
							        MTTasker tarefa= new MTTasker(app, font);
							        painelDone.addChild(tarefa);
							        tarefa.setTipo("DONE");
							        tarefa.setFillColor(textAreaColor);
							        tarefa.setAnchor(PositionAnchor.UPPER_LEFT);
							        tarefa.setPositionRelativeToParent(painelDone.getPosition(TransformSpace.LOCAL));
							        tarefa.setStrokeColor(textAreaColor);
							        tarefa.setText(t1.getText());
									clearAllGestures(tarefa);
									tarefa.registerInputProcessor(new DragProcessor(app));
									tarefa.addGestureListener(DragProcessor.class, new DefaultDragAction());
									tarefa.addGestureListener(DragProcessor.class, new InertiaDragAction()); //Add inertia to dragging
									tarefa.setPositionGlobal(new Vector3D(painelDone.getWidthXY(TransformSpace.RELATIVE_TO_PARENT)+410, p1*verticalPad+20,0));
									p1++;
									
							        doneList.add(tarefa); 
							        							        							        
							        t1.clear();
									break;
								default:
									break;
								}
							}
						}
					});
					keyb3.addChild(flickrButton1);
					
					getCanvas().addChild(keyb3);
					keyb3.setPositionGlobal(new Vector3D(app.width/2f, app.height/2f,0));
					
					
					System.out.println("Flickr search for: \"" + t1.getText() + "\"");	
					break;
				//case TapEvent.:
					
				default:
					break;
				}
			}
		});
		
		
		/*
		MTComponent topLayer = new MTComponent(app, "top layer group", new MTCamera(app));
		
		//Load from file system
		PImage keyboardImg1 = app.loadImage("advanced" + MTApplication.separator + "flickrMT"+ MTApplication.separator + "data"+ MTApplication.separator 
				+ "keyb128.png");
		
		final MTImageButton keyboardButton = new MTImageButton(keyboardImg1, app);
		keyboardButton.setFillColor(new MTColor(255,255,255,200));
		keyboardButton.setName("KeyboardButton");
		keyboardButton.setNoStroke(true);
		keyboardButton.setSizeLocal(50, 50);
		//keyboardButton.translateGlobal(new Vector3D(100,100,0));
		keyboardButton.translateGlobal(new Vector3D(-2,app.height-keyboardButton.getWidthXY(TransformSpace.GLOBAL)+2,0));
		topLayer.addChild(keyboardButton);
		
		keyboardButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae) {
				switch (ae.getID()) {
				case TapEvent.BUTTON_CLICKED:
					//Flickr Keyboard
			        MTKeyboard keyb = new MTKeyboard(app);
			        keyb.setFillColor(new MTColor(30, 30, 30, 210));
			        keyb.setStrokeColor(new MTColor(0,0,0,255));
			        
			        final MTTextArea t = new MTTextArea(app, FontManager.getInstance().createFont(app, "arial.ttf", 50, 
			        		new MTColor(0,0,0,255), //Fill color 
							new MTColor(0,0,0,255))); //Stroke color
			        t.setExpandDirection(ExpandDirection.UP);
					t.setStrokeColor(new MTColor(0,0 , 0, 255));
					t.setFillColor(new MTColor(205,200,177, 255));
					t.unregisterAllInputProcessors();
					t.setEnableCaret(true);
					t.snapToKeyboard(keyb);
					keyb.addTextInputListener(t);
			        
			        //Flickr Button for the keyboard
			        MTSvgButton flickrButton = new MTSvgButton( "advanced" + MTApplication.separator +  "flickrMT" + MTApplication.separator + "data" + MTApplication.separator
							+ "Flickr_Logo.svg", app);
			        flickrButton.scale(0.4f, 0.4f, 1, new Vector3D(0,0,0), TransformSpace.LOCAL);
			        flickrButton.translate(new Vector3D(0, 15,0));
			        flickrButton.setBoundsPickingBehaviour(AbstractShape.BOUNDS_ONLY_CHECK);

			      //Add actionlistener to flickr button
			        flickrButton.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent arg0) {
							if (arg0.getSource() instanceof MTComponent){
								//MTBaseComponent clickedComp = (MTBaseComponent)arg0.getSource();
								switch (arg0.getID()) {
								case TapEvent.BUTTON_CLICKED:
									//Get current search parameters
							        SearchParameters sp = new SearchParameters();
							        //sp.setSafeSearch("213on");
							        
							        //sp.setMachineTags(new String[]{"geo:locality=\"san francisco\""});
							        sp.setText(t.getText());
							        //sp.setTags(new String[]{t.getText()});
							        sp.setSort(SearchParameters.RELEVANCE);
							        
							        System.out.println("Flickr search for: \"" + t.getText() + "\"");
							        
							        //Load flickr api key from file
							        String flickrApiKey = "";
							        String flickrSecret = "";
							        Properties properties = new Properties();
							        try {
							        	InputStream in = null;
							        	try {
							        		in = new FileInputStream( "examples" + MTApplication.separator + "advanced" + MTApplication.separator + "flickrMT" + MTApplication.separator + "data" + MTApplication.separator + "FlickrApiKey.txt");
										} catch (Exception e) {
											System.err.println(e.getLocalizedMessage());
										}
										
							        	if (in == null){
							        		try {
							        			in = Thread.currentThread().getContextClassLoader().getResourceAsStream("advanced" + MTApplication.separator + "flickrMT" + MTApplication.separator + "data" + MTApplication.separator + "FlickrApiKey.txt");
											} catch (Exception e) {
												System.err.println(e.getLocalizedMessage());
											}
							        	}
							        	properties.load(in);

							        	flickrApiKey = properties.getProperty("FlickrApiKey", " ");
							        	flickrSecret = properties.getProperty("FlickrSecret", " ");
								    } catch (Exception e) {
								    	System.err.println("Error while loading FlickrApiKey.txt file.");
								    	e.printStackTrace();
								    	
								    }
							        
							        //Create flickr loader thread
							        final FlickrMTFotoLoader flickrLoader = new FlickrMTFotoLoader(app, flickrApiKey, flickrSecret, sp, 300);
							        //final FlickrMTFotoLoader flickrLoader = new FlickrMTFotoLoader(app, "pballardgentil", "alegria", sp, 300);
							        flickrLoader.setFotoLoadCount(5);
							        //Define action when loader thread finished
							        flickrLoader.addProgressFinishedListener(new IMTEventListener(){
										public void processMTEvent(MTEvent mtEvent) {
											//Add the loaded fotos in the main drawing thread to
											//avoid threading problems
											registerPreDrawAction(new IPreDrawAction(){
												public void processAction() {
													MTImage[] fotos = flickrLoader.getMtFotos();
													for (int i = 0; i < fotos.length; i++) {
														MTImage card = fotos[i];
														card.setUseDirectGL(true);
														card.setDisplayCloseButton(true);
														card.setPositionGlobal(new Vector3D(ToolsMath.getRandom(10, MT4jSettings.getInstance().getWindowWidth()-100), ToolsMath.getRandom(10, MT4jSettings.getInstance().getWindowHeight()-50),0 )  );
														card.scale(0.6f, 0.6f, 0.6f, card.getCenterPointLocal(), TransformSpace.LOCAL);
														card.addGestureListener(DragProcessor.class, new InertiaDragAction());
//														lassoProcessor.addClusterable(card); //make fotos lasso-able
//														pictureLayer.addChild(card);
													}

												}
												
												public boolean isLoop() {
													return false;
												}
											});
										}
							        });

							        //Run the thread
							        flickrLoader.start();
							        //Clear textarea
							        t.clear();
									break;
								default:
									break;
								}
							}
						}
					});
					keyb.addChild(flickrButton);
					
					getCanvas().addChild(keyb);
					keyb.setPositionGlobal(new Vector3D(app.width/2f, app.height/2f,0));
					
					
					System.out.println("Flickr search for: \"" + t.getText() + "\"");	
					break;
				//case TapEvent.:
					
				default:
					break;
				}
			}
		});*/

		
		//this.getCanvas().addChild(topLayer);
		//teste
        /*MTList lista = new MTList(app.width - 220,app.height - 503, app.width - 800, app.height - 269, app);
        getCanvas().addChild(lista); 
        MTListCell cell = new MTListCell(1, 1, app);
        MTTextArea area = new MTTextArea(app,font);
        area.setText("email");
        cell.addChild(area);
        lista.addListElement(cell);*/
        
		//Button to get to the next scene
				PImage arrow = mtApplication.loadImage(imagePath +	"arrowRight.png");
				MTImageButton nextSceneButton = new MTImageButton(arrow, mtApplication);
				nextSceneButton.setNoStroke(true);
				if (MT4jSettings.getInstance().isOpenGlMode())
					nextSceneButton.setUseDirectGL(true);
				nextSceneButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent ae) {
						switch (ae.getID()) {
						case TapEvent.BUTTON_CLICKED:
							//Save the current scene on the scene stack before changing
							app.pushScene();
							if (scene2 == null){
								scene2 = new Scene2(app, "Scene 2");
								//Add the scene to the mt application
								app.addScene(scene2);
							}
							//Do the scene change
							app.changeScene(scene2);
							break;
						default:
							break;
						}
					}
				});
				getCanvas().addChild(nextSceneButton);
				nextSceneButton.setPositionGlobal(new Vector3D(app.width - nextSceneButton.getWidthXY(TransformSpace.GLOBAL) - 5, app.height - nextSceneButton.getHeightXY(TransformSpace.GLOBAL) - 5, 0));
			
	}
	

	private void clearAllGestures(MTComponent comp){
		comp.unregisterAllInputProcessors();
		comp.removeAllGestureEventListeners();
	}
	
	//private MTTextArea 
	
	@Override
	public void init() {

	}

	@Override
	public void shutDown() {

	}
	

	
	

}
